<?php
require_once '../classes/class.relatorios.php';
require_once '../classes/class.IO.php';
require_once '../classes/class.funcoes.php';

$ClsRel = new Relatorios();
$ClsFunc = new Funcoes();

$cCurso = $_POST["cCurso"];
$cTurma = $_POST["cTurma"];
$cNome = $_POST["cNome"];
$cCpf = $_POST["cCpf"];

$cIO = new IO();
$cIO->Erase_Files("../temp");

$RelHist = $ClsRel->ReportHistorico($cCurso, $cTurma, $cNome, $cCpf);

if(is_resource($RelHist))
    if(mysql_num_rows($RelHist) > 0)
    {
        require_once '../tfpdf.php';
        $pdf = new tFPDF("L", "mm");
        $pdf->Open();
        $pdf->AddPage();
        
        $pdf->SetFont('Arial', 'B', 10);
        
        $relData = date("Y-m-d");
        $RelCaption = "Relatório de Totalização de Alunos Anual";
       
        $pdf->Cell(0, 30, utf8_decode($RelCaption), 0, 0, 'C');
        $pdf->ln();
        $pdf->Cell(30, 5, utf8_decode('Data: ') . $relData , 0, 0, 'L');
        $pdf->ln();

        $pdf->SetFont('Arial', 'B', 10);
        $pdf->Cell(60, 5, utf8_decode('Nome'), 1);
        $pdf->Cell(50, 5, utf8_decode('E-Mail'), 1);
        $pdf->Cell(20, 5, utf8_decode('Aulas'), 1, 0, "R");
        $pdf->Cell(20, 5, utf8_decode('Presenças'), 1, 0, "R");
        $pdf->Cell(20, 5, utf8_decode('Faltas'), 1, 0, "R");
        $pdf->Cell(20, 5, utf8_decode('% Presenças'), 1, 0, "R");
        $pdf->Cell(30, 5, utf8_decode('Situação'), 1, 0, "R");

        $pdf->SetFont('Arial', '', 10);
        while ($resultado = mysql_fetch_array($RelHist))
        {
            $pdf->ln();
            $pdf->Cell(60, 5, utf8_decode($resultado['Nome']), 1);
            $pdf->Cell(50, 5, utf8_decode($resultado['EMail']), 1);
            $pdf->Cell(20, 5, utf8_decode($resultado['Total Aulas']), 1, 0, "R");
            $pdf->Cell(20, 5, utf8_decode($resultado['Presenca']), 1, 0, "R");
            $pdf->Cell(20, 5, utf8_decode($resultado['Falta']), 1, 0, "R");
            $pdf->Cell(20, 5, utf8_decode($resultado['%']), 1, 0, "R");
            $pdf->Cell(30, 5, utf8_decode($resultado['Situacao']), 1, 0, "R");
        }
        $DateNow = date('dmY_His');      
        $namefill = "../temp/". $DateNow . ".pdf";
        $pdf->Output($namefill, "F");
        echo "temp/" . $DateNow . ".pdf";
    }
?>